<template>
  <section class="finance">
    <el-card class="box-card">
      <div slot="header" class="clearfix">
        来吧
      </div>
      <div class="text item">
        <ul><li v-for="(item, index) in numList" :key="index">{{ item }}</li></ul>
        <el-button @click="generateNumList">生成1-10</el-button>
      </div>
    </el-card>
  </section>
</template>
<script>
export default {
  data () {
    return {
      numList: [],
      numList2: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
      R: {
        record_groups: [{ // 判断条件
          title: '跟进情况',
          list: [{
            title: '跟进方式',
            key: 'record_type'
          },
          {
            title: '是否成功联系',
            key: 'record_contact',
            add: { // 选中 成功联系=1 时新增form的属性，取消反之
              target: 1,
              new_attr: ['record_order']
            }
          },
          {
            title: '是否下单成功',
            key: 'record_order',
            show: {
              key: 'record_contact',
              target: 1 // 成功联系才展示
            },
            add: { // 选中 未下单=1 时新增属性，取消反之
              target: 1,
              new_attr: ['record_will', 'record_account', 'record_price', 'record_date', 'record_reason', 'record_answer']
            }
          }]
        }, {
          title: '用户需求',
          list: [{
            title: '用户借款意愿',
            key: 'record_will',
            changer: {
              target: 1, // 暂无意愿，设置默认值
              default: [{
                key: 'record_account',
                value: 5
              }, {
                key: 'record_price',
                value: 6
              }, {
                key: 'record_date',
                multiple: true,
                value: [8]
              }]
            }
          },
          {
            title: '需借款金额',
            key: 'record_account'
          },
          {
            title: '可接受定价',
            key: 'record_price'
          },
          {
            title: '可接受借款期限',
            key: 'record_date',
            multiple: true
          }],
          show: {
            key: 'record_order',
            target: 1 // 未下单才展示
          }
        }, {
          title: '用户调研',
          list: [{
            title: '你认为用户不下单的核心原因是',
            key: 'record_reason'
          }, {
            title: '你认为一下哪项策略最能促动该用户下单',
            key: 'record_answer'
          }],
          show: {
            key: 'record_order',
            target: 1 // 未下单才展示
          }
        }],
        record_popup: {
          record_type: [{
            value: 1,
            title: '电话沟通'
          }, {
            value: 2,
            title: '微信/短信联系'
          }, {
            value: 3,
            title: '上门'
          }, {
            value: 4,
            title: '其他'
          }],
          record_contact: [{
            value: 1,
            title: '是'
          }, {
            value: 2,
            title: '否'
          }],
          record_order: [{
            value: 1,
            title: '未下单'
          }, {
            value: 2,
            title: '已下单'
          }],
          record_will: [{
            value: 1,
            title: '暂无意愿，直接拒绝'
          }, {
            value: 2,
            title: '意愿一般，可持续沟通'
          }, {
            value: 3,
            title: '意愿强烈，有借款需求'
          }],
          record_account: [{
            value: 1,
            title: '(0, 10000]元'
          }, {
            value: 2,
            title: '(10000, 50000]元'
          }, {
            value: 3,
            title: '(50000, 100000]元'
          }, {
            value: 4,
            title: '10万元以上'
          }, {
            value: 5,
            title: '未提及'
          }],
          record_price: [{
            value: 1,
            title: '(0, 15%]'
          }, {
            value: 2,
            title: '(0, 18%]'
          }, {
            value: 3,
            title: '(0, 24%]'
          }, {
            value: 4,
            title: '(0, 27%]'
          }, {
            value: 5,
            title: '(0, 36%]'
          }, {
            value: 6,
            title: '未提及'
          }],
          record_date: [{
            value: 1,
            title: 3
          }, {
            value: 2,
            title: 6
          }, {
            value: 3,
            title: 9
          }, {
            value: 4,
            title: 12
          }, {
            value: 5,
            title: 18
          }, {
            value: 6,
            title: 24
          }, {
            value: 7,
            title: 36
          }, {
            value: 8,
            title: '未提及'
          }],
          record_reason: [{
            value: 1,
            title: '定价过高'
          }, {
            value: 2,
            title: '借款金额不满足'
          }, {
            value: 3,
            title: '借款期限不满足'
          }, {
            value: 4,
            title: '用户近期没有借款需求'
          },  {
            value: 5,
            title: '对分期乐不信任'
          }, {
            value: 6,
            title: '其他'
          }],
          record_answer: [{
            value: 1,
            title: '提高额度'
          }, {
            value: 2,
            title: '降低定价'
          }, {
            value: 3,
            title: '延长借款期限'
          }, {
            value: 4,
            title: '需要些利益激励(如优惠券，还款券，实物礼品等)'
          }, {
            value: 5,
            title: '其他'
          }]
        },
        record_form: {
          record_type: 0,
          record_contact: 0
        }
      }
    }
  },
  created () {
    this.submitParams()
  },
  methods: {
    generateNumList () {
      let numList = []
      for (let i = 1; i < 11; i ++) {
        numList.push(i)
      }
      this.numList = numList
    },
    submitParams () {
      const forms = Object.keys(this.R.recordForm)
      let questionInfoDTOList = []
      forms.forEach(v => {
        let curItemInGroup = null
        this.R.recordGroups.forEach(g => {
          const target = g.list.filter(l => l.key === v)
          if (target && target.length) {
            curItemInGroup = target[0]
            return false
          }
        })
        let curItemInPopup = null
        if (curItemInGroup.multiple) {
          curItemInPopup = this.R.recordPopup[v].filter(p => this.R.recordForm[v].includes(p.value))
        } else {
          curItemInPopup = this.R.recordPopup[v].filter(p => this.R.recordForm[v] === p.value)
        }
        questionInfoDTOList.push({
          questionKey: v,
          questionDesc: curItemInGroup.title,
          questionChooseDTOList: curItemInPopup.map(c => {
            return {
              chooseDesc: c.title,
              chooseValue: c.value
            }
          })
        })
      })
      console.log('===', questionInfoDTOList)
    }
  }
}
</script>